package day03;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoRedirect extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.sendRedirect("http://baidu.com");
		resp.setStatus(HttpServletResponse.SC_FOUND);
		//重定向到url位request的servlet上
		//如何让重定向的时能够传递参数
		//先在这里获取到name 信息，然后加到url地址后面
		String parameter = req.getParameter("name");
//		System.out.println(parameter);
		//注意：中文直接加在地址后面会出现乱码
		//进行如下转码
		URLEncoder.encode(parameter,"utf-8");
		resp.setHeader("Location", "request?name="+URLEncoder.encode(parameter,"utf-8"));
	}
}
